package com.sense.kukoo.biz_explore.adapter.provider

import com.alibaba.android.arouter.utils.TextUtils
import com.sense.kukoo.biz_explore.adapter.MusicCollectionAdapter
import com.sense.kukoo.common.R
import com.sense.kukoo.common.repo.bean.BookBean
import com.sense.kukoo.common.repo.bean.MusicCollectionBean
import com.sense.kukoo.common.utils.ApplicationContext
import com.sense.kukoo.common.wiget.MusicCollectionItemView
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder
import com.sense.kukoo.lib_logger.LoggerManager

class MusicCollectionItemProvider(val listener: MusicCollectionAdapter.MusicCollectionEventListener) :
    MultiItemProvider<MusicCollectionBean>() {

    override fun getItemType(): Int = MusicCollectionBean.TYPE_DEF

    override fun getItemLayoutId(): Int = R.layout.common_music_collection_item_container

    override fun onBindViewHolder(viewHolder: BaseViewHolder, bean: MusicCollectionBean) {
        val book = bean.book

        val view = viewHolder.getView(R.id.item) as MusicCollectionItemView
        view.setItemClickListener {
            listener.onItemClick(book, viewHolder.adapterPosition)
        }
        //
        view.setIconUrl(book.coverUrl)

        when (bean.book.type) {
            BookBean.TYPE_UNKNOW -> {
                view.setType(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.explore_type_unknow))
            }
            BookBean.TYPE_AUDIOBOOK -> {
                view.setType(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.explore_type_audiobook))
            }
            BookBean.TYPE_PODCAST -> {
                view.setType(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.explore_type_podcast))
            }
            BookBean.TYPE_SHORT_AUDIO -> {
                view.setType(ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.explore_type_short_audio))
            }
            else -> {}
        }
        val name = if (TextUtils.isEmpty(book.alias)) book.name else book.alias
        view.setDes(name)
        view.setMsg("${book.subscribers}")
    }
}